﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{
    [Table(Name = "dbo.CJ")]
    public partial class CJ :Entity
    {

        private decimal _cjdNum;

        private string _xsId;

        private decimal _kmNum;

        private double _cj;

        private DateTime _date;

        private EntityRef<KM> _KM;

        private EntityRef<XS> _XS;

        public CJ()
        {
            this._KM = default(EntityRef<KM>);
            this._XS = default(EntityRef<XS>);
        }

        [Column(Storage = "_cjdNum", AutoSync = AutoSync.OnInsert, DbType = "Decimal(18,0) NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public decimal CJDNum
        {
            get
            {
                return this._cjdNum;
            }
            set
            {
                if ((this._cjdNum != value))
                {
                    this.SendPropertyChanging("CJDNum");
                    this._cjdNum = value;
                    this.SendPropertyChanged("CJDNum",value);
                }
            }
        }

        [Column(Storage = "_xsId", DbType = "VarChar(20)")]
        public string XSId
        {
            get
            {
                return this._xsId;
            }
            set
            {
                if ((this._xsId != value))
                {
                    if (this._XS.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("XSId");
                    this._xsId = value;
                    this.SendPropertyChanged("XSId",value);
                }
            }
        }

        [Column(Storage = "_kmNum", DbType = "Decimal(18,0)")]
        public decimal KMNum
        {
            get
            {
                return this._kmNum;
            }
            set
            {
                if ((this._kmNum != value))
                {
                    if (this._KM.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("KMNum");
                    this._kmNum = value;
                    this.SendPropertyChanged("KMNum",value);
                }
            }
        }

        [Column(Storage = "_cj", DbType = "Float")]
        public double Score
        {
            get
            {
                return this._cj;
            }
            set
            {
                if ((this._cj != value))
                {
                    this.SendPropertyChanging("Score");
                    this._cj = value;
                    this.SendPropertyChanged("Score",value);
                }
            }
        }

        [Column(Storage = "_date", DbType = "DateTime")]
        public DateTime Date
        {
            get
            {
                return this._date;
            }
            set
            {
                if ((this._date != value))
                {
                    this.SendPropertyChanging("Date");
                    this._date = value;
                    this.SendPropertyChanged("Date",value);
                }
            }
        }

        [Association(Name = "KM_CJ", Storage = "_KM", ThisKey = "KMNum", OtherKey = "KMNum", IsForeignKey = true)]
        public KM KM
        {
            get
            {
                return this._KM.Entity;
            }
            set
            {
                KM previousValue = this._KM.Entity;
                if (((previousValue != value)
                            || (this._KM.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("KM");
                    if ((previousValue != null))
                    {
                        this._KM.Entity = null;
                        previousValue.CJ.Remove(this);
                    }
                    this._KM.Entity = value;
                    if ((value != null))
                    {
                        value.CJ.Add(this);
                        this._kmNum = value.KMNum;
                    }
                    else
                    {
                        this._kmNum = default(decimal);
                    }
                    this.SendPropertyChanged("KM",value);
                }
            }
        }

        [Association(Name = "XS_CJ", Storage = "_XS", ThisKey = "XSId", OtherKey = "XSId", IsForeignKey = true)]
        public XS XS
        {
            get
            {
                return this._XS.Entity;
            }
            set
            {
                XS previousValue = this._XS.Entity;
                if (((previousValue != value)
                            || (this._XS.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("XS");
                    if ((previousValue != null))
                    {
                        this._XS.Entity = null;
                        previousValue.CJ.Remove(this);
                    }
                    this._XS.Entity = value;
                    if ((value != null))
                    {
                        value.CJ.Add(this);
                        this._xsId = value.XSId;
                    }
                    else
                    {
                        this._xsId = default(string);
                    }
                    this.SendPropertyChanged("XS",value);
                }
            }
        }
    }
	
}
